package com.lucenten.collect.config.entity;

import cn.quevo.common.entity.DoEntity;
import cn.quevo.common.enums.ResultStatusEnum;
import cn.quevo.common.exception.CheckParamsException;
import cn.quevo.common.lang.RegularUtils;
import cn.quevo.common.lang.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.beetl.sql.core.annotatoin.Table;

/**
 * 采集设置 实体BEAN
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2019/04/27 11:04:02
 * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
 */
@ApiModel(value = "CollectConf 采集设置")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Table(name = "t_collect_conf")
public class CollectConf extends DoEntity {

    /** 服务器名称 */
    @ApiModelProperty(value = "服务器名称",required = true)
    private String serverName;
    /** 服务器IP */
    @ApiModelProperty(value = "服务器IP")
    private String serverIp;
    /** 服务器编号 */
    @ApiModelProperty(value = "服务器编号")
    private String serverCode;
    /** 线程数量 */
    @ApiModelProperty(value = "线程数量")
    private Integer threadQty;
    /** 处理站点数量 */
    @ApiModelProperty(value = "处理站点数量")
    private Integer stationQty;
    /** 是否启用 */
    @ApiModelProperty(value = "是否启用")
    private String enabledYn;

    /**
    * 公共参数验证
    */
    protected void validate() {
        if(StringUtils.isBlank(this.getServerName())){
            throw new CheckParamsException(6001, "服务器名称不能为空");
        }
        if(StringUtils.isBlank(this.getServerIp())){
            throw new CheckParamsException(6002, "服务器IP不能为空");
        }
        if(StringUtils.isBlank(this.getServerCode())){
            throw new CheckParamsException(6003, "服务器编号不能为空");
        }
        if(StringUtils.isBlank(this.getThreadQty())){
            throw new CheckParamsException(6004, "线程数量不能为空");
        }
        if(StringUtils.isBlank(this.getStationQty())){
            throw new CheckParamsException(6005, "处理站点数量不能为空");
        }
        if(StringUtils.isBlank(this.getEnabledYn())){
            throw new CheckParamsException(6006, "是否启用不能为空");
        }
    }

    /**
    * 新增参数验证
    */
    public void validateCreate() {
        this.validate();
    }

    /**
    * 修改参数验证
    */
    public void validateUpdate() {
        if (StringUtils.isBlank(this.getId())) {
            throw new CheckParamsException(ResultStatusEnum.RECORD_UNSELECTED);
        }
        this.validate();
    }
}
